package graphics;

import java.awt.Dimension;
import java.awt.Point;
import willispace.Config;

/**
 * Windows Manager.
 * Initializes all windows and keep references to them.
 * @author mateusz
 */
public class WindowManager {

    /**
     * name of main window
     */
    public final static String mainWindowName = "WilliSpace";
    /**
     * name of entity window
     */
    public final static String entityWindowName = "Entity";
    /**
     * name of control window
     */
    public final static String controlWindowName = "Control";
    // entity window properties
    private final static int sideWindowsWidth = 350;
    private final static float sideWindowsHeightRatio = 0.83f;
    private final static int sideWindowsSpace = 10;
    // windows references
    /**
     * reference to fullscreen window
     */
    public static FullScreenWindow fullScreenWindow = null;
    /**
     * reference to entity window
     */
    public static EntityWindow entityWindow = null;
    /**
     * reference to control window
     */
    public static ControlWindow controlWindow = null;
    
    /**
     * initializes all windows
     */
    public static void init() {
        // prepare dimensions
        Dimension screenSize = getScreenSize();
        Config.horizontalTiles = ( int ) ( ( screenSize.width - sideWindowsWidth - 2
                * sideWindowsSpace ) / Config.tileWidth );
        Config.verticalTiles = ( int ) ( ( screenSize.height - 2 * sideWindowsSpace )
                / Config.tileHeight );

        // entity window properites
        int entityWindowHeight = ( ( int ) ( ( float ) screenSize.height
                * sideWindowsHeightRatio ) ) - 2 * sideWindowsSpace;
        int sideWindowPositionX = screenSize.width - sideWindowsWidth
                - sideWindowsSpace;

        Dimension entityWindowSize = new Dimension( sideWindowsWidth,
                entityWindowHeight );
        Point entityWindowStart = new Point( sideWindowPositionX,
                sideWindowsSpace*2 );

        entityWindow = new EntityWindow( entityWindowName, entityWindowSize,
                entityWindowStart );

        // control window properties
        Dimension controlWindowSize = new Dimension( sideWindowsWidth,
                screenSize.height - entityWindowHeight - 4 * sideWindowsSpace );
        Point controlWindowStart = new Point( sideWindowPositionX, entityWindowHeight
                + 4 * sideWindowsSpace );

        controlWindow = new ControlWindow(
                controlWindowName, controlWindowSize, controlWindowStart );

        // fullscreen window properties
        Dimension fullScreenSize = screenSize;
        Point fullScreenStart = new Point( 0, 0 );

        Dimension fullScreenMainPanelSize = new Dimension( Config.horizontalTiles
                * Config.tileWidth, Config.verticalTiles * Config.tileHeight );

        fullScreenWindow = new FullScreenWindow( mainWindowName, fullScreenSize,
                fullScreenStart, fullScreenMainPanelSize );
    }

    /**
     * Returns fullscreen window size
     * @return screen size
     */
    public static Dimension getScreenSize() {
        return java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        //return new Dimension( 1300, 720 );
    }

    public static void setMapSize(int width, int height){
        Dimension size = new Dimension(width, height);
        CustomWindow.setPanelSize(fullScreenWindow.mainPanel, size);
        CustomWindow.setPanelSize(fullScreenWindow.bottomPanel, size);
        CustomWindow.setPanelSize(fullScreenWindow.middlePanel, size);
        CustomWindow.setPanelSize(fullScreenWindow.topPanel, size);
    }
}
